Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Collections.ObjectModel
Imports Microsoft.Xna.Framework


Public Class TileState

	Private Const iSize As Integer = 2
	Private data As New Queue(Of StateTileElement)(iSize)

	Public Sub New()
		Add(New StateTileElement())
	End Sub

	Public Function [Next]() As Enumeration.StateTile
		Return [Next](Value().state)
	End Function
	Public Function [Next](state As Enumeration.StateTile) As Enumeration.StateTile
		Select Case state
			Case Else
				'case Enumeration.StateTile.freefall:
				'    return Enumeration.StateTile.crouch;
				Return Enumeration.StateTile.normal
		End Select

	End Function


	Public Sub Add(state As Enumeration.StateTile)
		'if (Value().state == state)
		'    return;

		If data.Count = iSize Then
			data.Dequeue()
		End If

		data.Enqueue(New StateTileElement(state))
	End Sub

	Public Sub Add(state As Enumeration.StateTile, ifTrue As Boolean)
		'if (Value().state == state)
		'    return;

		If data.Count = iSize Then
			data.Dequeue()
		End If

		data.Enqueue(New StateTileElement(state, ifTrue))
	End Sub

	Public Sub Add(state As Enumeration.StateTile, priority As Enumeration.PriorityState)
		If data.Count = iSize Then
			data.Dequeue()
		End If

		data.Enqueue(New StateTileElement(state, priority))
	End Sub

	Public Sub Add(state As Enumeration.StateTile, priority As Enumeration.PriorityState, reverse As Enumeration.SequenceReverse)
		If data.Count = iSize Then
			data.Dequeue()
		End If

		data.Enqueue(New StateTileElement(state, priority, reverse))
	End Sub

	Public Sub Add(state As Enumeration.StateTile, priority As Enumeration.PriorityState, stoppable As System.Nullable(Of Boolean))
		If data.Count = iSize Then
			data.Dequeue()
		End If

		data.Enqueue(New StateTileElement(state, priority, stoppable, Enumeration.SequenceReverse.Normal))
	End Sub

	Public Sub Add(state As Enumeration.StateTile, priority As Enumeration.PriorityState, stoppable As System.Nullable(Of Boolean), offSet As Vector2)
		If data.Count = iSize Then
			data.Dequeue()
		End If

		data.Enqueue(New StateTileElement(state, priority, stoppable, Enumeration.SequenceReverse.Normal, offSet))
	End Sub

	Public Sub Add(state As Enumeration.StateTile, priority As Enumeration.PriorityState, stoppable As System.Nullable(Of Boolean), reverse As Enumeration.SequenceReverse)
		If data.Count = iSize Then
			data.Dequeue()
		End If

		data.Enqueue(New StateTileElement(state, priority, stoppable, reverse))
	End Sub


	Public Sub Add(state As Enumeration.StateTile, priority As Enumeration.PriorityState, stoppable As System.Nullable(Of Boolean), reverse As Enumeration.SequenceReverse, offSet As Vector2)
		If data.Count = iSize Then
			data.Dequeue()
		End If

		data.Enqueue(New StateTileElement(state, priority, stoppable, reverse, offSet))
	End Sub


	Public Sub Add(stateElement As StateTileElement)
		If data.Count = iSize Then
			data.Dequeue()
		End If

		data.Enqueue(stateElement)
	End Sub

	Public Function Previous() As StateTileElement
		If data.Count = 0 Then
			Add(New StateTileElement())
		End If
		Return data.First()
	End Function


	Public Function Value() As StateTileElement
		If data.Count = 0 Then
			Add(New StateTileElement())
		End If
		Return data.Last()
	End Function

	Public Sub Clear()
		data.Clear()
	End Sub

	Public Function GetData() As IEnumerable(Of StateElement)
		' Need to go via array because Queue does not implement IList<T>
		' which ReadOnlyCollection's ctor takes.
		Return New ReadOnlyCollection(Of StateElement)(data.ToArray())
	End Function
End Class
